import { RequestHandler } from 'express'
import { failure, success } from '@/utils/response'
import authService from '@/services/authService'

const signUp: RequestHandler = async function (req, res) {
  try {
    const data = await authService.signUp(req.body)
    success(res, '创建用户成功。', data, 201)
  } catch (error) {
    failure(res, error as Error, '创建用户失败：')
  }
}

const signIn: RequestHandler = async function (req, res) {
  try {
    const data = await authService.signIn(req.body)
    success(res, '登录成功。', data)
  } catch (error) {
    failure(res, error as Error, '登录失败：')
  }
}

export default {
  signUp,
  signIn,
}
